Return type | Name and parameters |
---|---|
long[]
|
column(int col)
Select a column from a 2D array. |
long[][]
|
eachColumn(Closure closure)
Process the columns of the array. |
List
|
flatten()
Flattens a 2D array into a new collection. |
long[][]
|
transpose()
A transpose method for 2D long arrays. |
Iterator
|
transposing()
An iterator of the columns of the array. |
Select a column from a 2D array.
long[][] nums = [[1L, 2L], [10L, 20L]] assert nums.column(0) == [1L, 10L] as long[] assert nums.column(1) == [2L, 20L] as long[]
Process the columns of the array.
double[][] nums = [[1L, 2L], [10L, 20L]] nums.eachColumn { assert it[0] * 10L == it[1] }
closure
- the closure applied on each array columnFlattens a 2D array into a new collection. The items are copied row by row.
Example usage:
long[][] array = [[0, 1], [2, 3]] assert array.flatten() == [0, 1, 2, 3]
A transpose method for 2D long arrays.
Example usage:
long[][] longs = [[1L, 3L, 5L], [2L, 4L, 6L]] long[][] expected = [[1L, 2L], [3L, 4L], [5L, 6L]] def result = longs.transpose() assert result == expected assert longs.class.componentType == result.class.componentType
An iterator of the columns of the array.
long[][] nums = [[1L, 2L], [10L, 20L]] assert nums.transpose() == nums.transposing().toList() assert nums.transposing().collect{ long[] col -> col.sum() } == [11L, 22L]